#pragma once
#include "RBTree.h"

namespace real {
	template <class K, class T>
	class map
	{
		struct MapKeyOfT {
			const K& operator()(const std::pair<const K,T>& pv)
			{
				return pv.first ;
			}
		};
		RBTree<K, std::pair<const K,T>, MapKeyOfT> rb_tree;

	public:
		using iterator = typename RBTree<const K, std::pair<const K,T>, MapKeyOfT>::iterator;
		using const_iterator = typename RBTree<const K, std::pair<const K,T>, MapKeyOfT>::const_iterator;

		iterator begin() {
			return rb_tree.begin();
		}
		iterator end() {
			return rb_tree.end();
		}
		const_iterator begin() const {
			return rb_tree.begin();
		}
		const_iterator end() const {
			return rb_tree.end();
		}
		std::pair<iterator, bool> insert(const std::pair<const K, T>& pair_val) {
			return rb_tree.Insert(pair_val);
		}
		iterator find(const K& key) const {
			return rb_tree.Find(key);
		}
		T& operator[](const K& key)
		{
			std::pair<iterator, bool> pv = insert({key, T()});
			return pv.first->second;
		}
	};
}
